- /* slfdivnw.cpp by K.Tsuru */
- // function ID = 214 DRADIX
- /*************************************************
- SLong class only
- This is a protected member function which user cannot access.
- m/n by Newton method m and n both positive.
- q = m/n, r = m - q*n;
- m > n > 0, n > 1 etc. has been checked in LLDiv().
- *************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* const func = "NewtonLLDiv";
- Ldiv_t SLong::NewtonLLDiv(const SLong& m, const SLong& n, bool needRem){
- if( (m.Head() < n.Head()) || (m.Sign() <= 0) || (n.Sign() <= 0) ){
- m.SetError(m.SYNTAX_ERR, func, 214);
- }
- //check the radix
- if( (m.Radix() != DRADIX) || (n.Radix() != DRADIX) ){
- m.SetError(m.RADIX_ERR, func, 214);
- }
- uint inv_fig = m.Head()-n.Head()+2u; //necessary figures of 1/n
- RealSize C;
- C.SetEffFig(inv_fig);
-
- // SLong ---> SDouble conversion
- SDouble M(m), N(n);
- SLong q, r, one(1.0);
-
- M = M/N;
- q = M; // SDouble --> SLong conversion
- C.SetEffFig(0);
-
- //It corrects the quotient and remainder.
- //Almost an exact result is obtained.
- r = m - n*q;
- if(r.Sign(214) < 0){
- while(r.Sign(214) < 0){ // q is too large.
- q -= one; r += n;
- }
- } else {
- while(r >= n){ // q is too small.
- q += one; r -= n;
- }
- }
-
- if(!needRem) return q;
- return Ldiv_t(q, r); //The verify is done in LLDiv.
- }
slmdivnw.cpp : last modifiled at 2016/07/28 16:22:23(1,389 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).